<!--  frame 我的地址 -->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
  <meta name="divport" content="width=device-width,initial-scale=1,user-scalable=no" />
  <meta name="format-detection" content="telephone=no,email=no,date=no,address=no" />
	<title>我的地址</title>
	<link rel="stylesheet" href="../plugin/hhframe/hhframe.min.css" />
	<link rel="stylesheet" href="../style/index.css"/>

	<style>

	body {
	  /*background-color:#F8F8F8;*/
	}
	/* pages/address/address.wxss */

	.wrap {
	  margin-top: .20rem;
	  margin-bottom: 1.70rem;
	}

	.section {
	  background: #fff;
	  padding: 0 .30rem;
	  margin-bottom: .10rem;
	}

	.top_box {
	  padding: .36rem 0;
	}

	.flex_row {
	  display: flex;
	  align-items: center;
	}

	.mr_r_40 {
	  margin-right: .40rem;
	}

	.mr_r_60 {
	  margin-right: .60rem;
	}

	.userInfo {
	  margin-bottom: .15rem;
	}

	.font {
	  font-size: .28rem;
	  color: #666;
	}

	.user_title, .user_name, .user_phone {
	  height: .28rem;
	  line-height: .28rem;
	}

	.user_t_w, .addr_t_w {
	  width: 1.40rem;
	}

	.bott_box {
	  height: .95rem;
	  border-top: 1px solid #e5e5e5;
	  padding-right: .20rem;
	}

	.radio {
	  width: .34rem;
	  height: .34rem;
	  border-radius: 50%;
	  border: 1px solid #eee;
	  margin-right: .10rem;
	}
	.radio1 {
	  width: .34rem;
	  height: .34rem;
	  border-radius: 50%;
	  /*border: 1px solid #eee;*/
	  margin-right: .10rem;
	}

	.flex_auto {
	  height: .40rem;
	  flex: auto;
	  text-align: right;
		display: flex;
	}

	.check {
	  width: .34rem;
	  height: .34rem;
	  line-height: .34rem;
	  font-size: .34rem;
	  color: #27b700;
	}

	.delete, .edit {
	  width: .40rem;
	  height: .40rem;
	}

	.active {
	  color: #27b700;
	}

	.btn1 {
	  position: fixed;
		width: 100%;
		display: flex;
		justify-content: center;
	  left: 0;
	  bottom: 0;
	  background: #f5f5f5;
	}

	.addr {
	  width: 6.50rem;
	  height: .90rem;
	  line-height: .90rem;
	  font-size: .36rem;
	  background: #ff502d;
	  color: #fff;
		display: flex;
		justify-content: center;
	  margin-bottom: .50rem;
		border-radius: .1rem;
	}

	.bg {
	  opacity: 0.7;
	}
	.is_select{
		width: 5.5rem;
	}
.addr_box{
	display: flex;
}
	</style>
</head>
<body>
	<div class="content app" v-cloak>
		<!--pages/address/address.wxml-->

		<div class="wrap">
		  <div class="section" v-for="(item,index) in addressInfo" :key="index" @click="AddrChoose(item)" >
		    <div class="top_box">
		      <div class="userInfo flex_row">
		        <div class="user_title font user_t_w">收件人：</div>
		        <div class="user_name font mr_r_40">{{item.consignee}}</div>
		        <div class="user_phone font">{{item.phone}}</div>
		      </div>
		      <div class="addr_box">
		        <div class="addr_title font addr_t_w">收货地址：</div>
		        <div class="addr_content font">{{item.address}}</div>
		      </div>
		    </div>
		    <div class="bott_box flex_row">
		      <div class="is_select flex_row" v-if="item.is_default==1" >
		        <div class="radio1">
		          <div class="iconfont iconxuanze check" v-if="item.is_default==1"></div>
		        </div>
		        <div class="radio_text font active">默认收货地址</div>
		      </div>
					<div class="is_select flex_row" v-else @click.stop="amendAdderss(item.id)" >
						<div class="radio"></div>
						<div  class="radio_text font">设置为默认收货地址</div>
					</div>
		      <div class="flex_auto">
		        <image class="delete mr_r_60" src="../image/delete.png" @click.stop="delete1(item.id)"  ></image>
		        <image class="edit" src="../image/edit.png" @click.stop="my_address_edit(item.id)" ></image>
		      </div>
		    </div>
		  </div>
		</div>
		<div class="btn1">
		  <div class="addr" hover-class="bg" @click="my_address_new">新建地址</div>
		</div>
	</div>
</body>
<script src="../plugin/jquery.js"></script>
<script src="../plugin/vue.all.js"></script>
<script src="../plugin/hhframe/hhframe.min.js"></script>
<script src="../plugin/public.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
window.addEventListener("apiready",function(){
	index()
});

function index()
{
	var vm = new Vue({
		el: ".app",
		data: {
			idx: null,
	    addressInfo:[],
			isbz:false,
	    //根据参数判断从哪个页面进来
	    addr_parameter:api.pageParam.id,

		},
		mounted: function(){
					this.getData()
				// 监听页面打开
				api.addEventListener({
				    name: 'viewappear'
				}, function(ret, err) {
					if(vm.isbz){
						vm.getData(false)
					}
				});
				this.isbz = true
		},
		methods: {

			//获取收货地址
				getData: function (loader){
					AjaxSafe({
				   		url:"/xapp/user/findUserAddress",
				    	loader:loader,
						success: function(ret) {
							let addressInfo = (ret || []).map(function(item) {
								return item
							})
							for (var i = 0; i < addressInfo.length;i++){
								if (addressInfo[i].is_default==1){
								}
							}
								vm.addressInfo = addressInfo
						},
						failed: function(err){
								alert("网络故障！");
						}
					});
				},
				//设置默认地址
					amendAdderss: function (id){
						let param = {
				      address_id: id
						}
						AjaxSafe({
					   		url:'/xapp/user/changeDefaultAdd',
								data:param,
					    	loader:true,
							success: function(res) {
								api.toast({msg: res.msg,duration: 2000,location: 'middle'});
								vm.getData(false)
							},
							failed: function(err){
									alert("网络故障！");
							}
						});
					},
					// 选择地址
					AddrChoose(item){
						if(this.addr_parameter){
							api.sendEvent({
							    name: 'select_address',
							    extra: {
							        item: item,
							    }
							});
							api.closeWin();
						}
					},
				//删除收货地址
					delete1: function (id){
						console.log(1);
						hhPanel.confirm({
						    title: "提示",
						    content: "确定删除该收货地址？",
						    btns: ["取消","确定"]
						},function () {
							let param = {
									address_id: id
							}
							AjaxSafe({
									url:"/xapp/user/delete",
									data:param,
									loader:true,
								success: function(ret) {
									if (ret.state) {
		                api.toast({msg: '删除成功！',duration: 2000,location: 'middle'});
										vm.getData(false)
										api.sendEvent({
										    name: 'delect_address',
										    extra: {
										        id: id,
										    }
										});
		              } else {
		                api.toast({msg: '删除失败！',duration: 2000,location: 'middle'});
		              }
								},
								failed: function(err){
										alert("网络故障！");
								}
							});
						});

					},





		},


	});
}

</script>
</html>
